﻿/*
* AnalysisFunc.cs
*
* 功 能： 智能诊断模块通用类
* 类 名： AnalysisFunc
*
* Ver    变更日期  20131125   负责人  黄永生  变更内容
* ───────────────────────────────────

*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DQYT.HTDZ.Common;
using DQYT.HTDZ.Model;
using DQYT.HTDZ.BLL;
using System.Data;
using DQYT.HTDZ.BusinessService;
using Maticsoft.DBUtility;

namespace DQYT.HTDZ.BusinessService
{
    public class AnalysisFunc
    {
        /// <summary>
        /// 获得采集基础数据model
        /// </summary>
        /// <param name="wellid"></param>
        /// <param name="jcrq"></param>
        /// <returns></returns>
        public BDDATESOURCEModel getdatesousemodel(string wellid, string jcrq)
        {
            DataSet ds = new DataSet();
            string sqlstr = "select ID from BDDATESOURSE where JCRQ=to_date( '" + jcrq + "','yyyy-MM-dd HH24:mi:ss ') and WELLID='" + wellid + "'";
            BDDATESOURSEBLL bll = new BDDATESOURSEBLL();
            ds = bll.GetList_SQL(sqlstr);
            decimal id = (decimal)ds.Tables[0].Rows[0][0];
            BDDATESOURCEModel model = new BDDATESOURCEModel();
            model = bll.GetModel(id);
            return model;


        }
        /// <summary>
        /// 获得特征值model
        /// </summary>
        /// <param name="wellid"></param>
        /// <param name="jcrq"></param>
        /// <returns></returns>
        public BDVALUEModel getValueModel(string wellid, string jcrq)
        {
            DataSet ds = new DataSet();
            string sqlstr = "select * from BDVALUE where JCRQ=to_date( '" + jcrq + "','yyyy-MM-dd HH24:mi:ss ') and WELLID='" + wellid + "'";
            BDVALUEBLL bll = new BDVALUEBLL();
            ds = bll.GetList_SQL(sqlstr);
            decimal id = (decimal)ds.Tables[0].Rows[0][0];
            BDVALUEModel model = new BDVALUEModel();
            model = bll.GetModel(id);
            return model;


        }
        /// <summary>
        /// 获得井号列表
        /// </summary>
        /// <returns></returns>
        public DataTable getWellidList()
        {
            DataSet ds = new DataSet();
            string sqlstr = "select  distinct WELLID,JCRQ FROM BDDATESOURSE order by JCRQ";
            BDDATESOURSEBLL bll = new BDDATESOURSEBLL();
            ds = bll.GetList_SQL(sqlstr);
            return ds.Tables[0];
        }
        /// <summary>
        /// 获得方案列表
        /// </summary>
        /// <returns></returns>
        public DataTable getSchemeList()
        {
            DataTable schemeTb = DbHelperOra.Query_Table("select SCHEME_NAME,SCHEME_ID from TB_Scheme");
            return schemeTb;
        }
        /// <summary>
        /// 获得相同井号的检测时间
        /// </summary>
        /// <returns></returns>
        public DataTable getWellJCRQ(string wellid)
        {
            DataSet ds = new DataSet();
            string sqlstr = "select JCRQ FROM BDDATESOURSE where WELLID='"+wellid+"' order by JCRQ";
            BDDATESOURSEBLL bll = new BDDATESOURSEBLL();
            ds = bll.GetList_SQL(sqlstr);
            return ds.Tables[0];
        }
        /// <summary>
        /// 获取采集数据
        /// </summary>
        /// <param name="wellid"></param>
        /// <param name="jcrq"></param>
        /// <returns></returns>
        public DataTable getCJSJTb(string wellid, string jcrq)
        {
            string strSql = "select CJSJ FROM BDDATESOURSE  where trim(WELLID)='" + wellid + "' and JCRQ = to_date( '" + jcrq + "','yyyy-MM-dd HH24:mi:ss ')";
            BDDATESOURSEBLL bll = new BDDATESOURSEBLL();
            DataTable drawTb = bll.GetList_SQL(strSql).Tables[0];//获得一条记录
            byte[] btCjsj = (byte[])drawTb.Rows[0]["CJSJ"];
            List<CJSJModel> cjsjModels = BinarySerializer.DeserializeObject<List<CJSJModel>>(btCjsj);
            BDCjsjFunc cjsjFunc = new BDCjsjFunc();
            drawTb = cjsjFunc.listCJSJModelToDataTable(cjsjModels);
            return drawTb;
        }

       
    
    }

}
